package com.coocaa.ops.admin.v1.timedtask.job.listener;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.listeners.JobListenerSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author bijiahao
 * @description
 * @date 2020/5/13 17:50
 */
public class RealTimeOnceJobListener extends JobListenerSupport {
    private static final Logger log = LoggerFactory.getLogger(RealTimeOnceJobListener.class);

    protected String myJobName;
    private Scheduler scheduler;

    public RealTimeOnceJobListener(String myJobName, Scheduler scheduler) {
        this.myJobName = myJobName;
        this.scheduler = scheduler;
    }

    @Override
    public String getName() {
        return myJobName;
    }

    @Override
    public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
        try {
            this.scheduler.deleteJob(context.getJobDetail().getKey());
            log.info("===== jobWasExecuted");
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
